import CryptoJS from 'crypto-js';
export default {
    /**
     * @description 加密
     * @param {*} message 数据
     * @param {string} text 文本
     * @return {*} 返回值
     */
    encryptByDES(message, text) {
        const keyHex = CryptoJS.enc.Utf8.parse('awebskey');
        const encrypted = CryptoJS.DES.encrypt(message, keyHex, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
        return encrypted.toString();
    },

    /**
     * @description 解密
     * @param {*} ciphertext 数据
     * @return {*} 返回值
     */
    decryptByDES(ciphertext) {
        const keyHex = CryptoJS.enc.Utf8.parse('awebskey');
        const decrypted = CryptoJS.DES.decrypt(
            {
                ciphertext: CryptoJS.enc.Base64.parse(ciphertext)
            },
            keyHex,
            {
                mode: CryptoJS.mode.ECB,
                padding: CryptoJS.pad.Pkcs7
            }
        );
        return decrypted.toString(CryptoJS.enc.Utf8);
    }
};
